﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZWZ.Web.WebAdmin
{
    public partial class Login : System.Web.UI.Page
    {
        /// <summary>
        /// 是否显示验证码
        /// </summary>
        public bool ShowIdentityCode { get { return Codes.IdtCodeHelper.ShowIdentyCode; } }
        private Codes.MessageBox MsgBox;
        protected string RawUrl { get { return Request["url"]; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            MsgBox = new Codes.MessageBox(this);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (Codes.IdtCodeHelper.Check(txtIdentCode.Text))
                {
                    if (Codes.LoginHelper.Login(txtEmail.Text, txtPassword.Text))
                    {
                        var admindir = Config.ConfigAdapter.SiteDataMgr.Groups["Req_PageDir"].Settings["DirAdmin"].Value;
                        //登录成功
                        if (!RawUrl.Contains("/WebAdmin/l.aspx"))
                        {
                            admindir = RawUrl;
                        }
                        Codes.LoggerHelper.AdminLogger.InfoFormat("{0}登录成功！", txtEmail.Text);
                        Response.Redirect(admindir);
                    }
                    else
                    {
                        MsgBox.Show("密码或用户名错误!");
                    }
                }
                else
                {
                    MsgBox.Show("验证码错误!");
                }
            }
            catch (Codes.ErrorCountException exp)
            {
                MsgBox.Show("登录次数过多，请稍后登录！");
            }
            catch (Exception exp)
            {
                MsgBox.Show("用户名或密码错误1");
            }
            MsgBox.Send();
        }
    }
}